/*******************************************************************************
 * Copyright (c) 2012, 2013 XML-Print Project.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     XML-Print Project - initial API and implementation
 ******************************************************************************/
package info.xmlprint.core.xml;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;

public class PAttribut implements Cloneable, Serializable {
	private static final long serialVersionUID = 459398877470896L;

	private String name = "";
	Set<String> attrSet = new HashSet<String>();

	public PAttribut(String s) {
		this.name = s;
	}

	public void addValue(String valueName) {
		attrSet.add(valueName);
	}

	public void setName(String s) {
		this.name = s;
	}

	public String getName() {
		return this.name;
	}

	public List<String> getList() {
		if (attrSet.size() < 1)
			return null;

		List<String> list = new ArrayList<String>();
		Iterator<String> it = attrSet.iterator();
		while (it.hasNext()) {
			list.add(it.next());
		}
		Collections.sort(list);
		return list;
	}

	public PAttribut clone() {
		PAttribut cloned = null;
		try {
			cloned = (PAttribut) super.clone();
		} catch (CloneNotSupportedException e) {
			Logger.getLogger(this.getClass().getName()).error("", e);
			e.printStackTrace();
		}
		return cloned;
	}
}
